package com.bdqn.rabbitmq;

import com.alibaba.fastjson.JSON;
import com.bdqn.base.Email;
import com.bdqn.base.Global;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * EmailMQServiceImpl
 *
 * @author LILIBO
 * @since 2024/4/12
 */
@Component
public class EmailMQServiceImpl implements EmailMQService {

    /**
     * 引入RabbitMQ操作对象
     */
    @Resource
    private RabbitTemplate rabbitTemplate;

    /**
     * 将邮件消息推送到RabbitMQ消息队列
     *
     * @param email
     */
    @Override
    public void publishMQMail(Email email) {
        rabbitTemplate.convertAndSend(Global.EXCHANGE_NAME_EMAIL, Global.ROUTING_KEY_EMAIL, JSON.toJSON(email));
    }

}
